package com.example.demo01.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo01.entity.User;
import com.example.demo01.mapper.OrderMapper;
import com.example.demo01.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserController {

    @Autowired
    private UserMapper userMapper;//这步非常关键


    @GetMapping("/user")
    public List GetUser(){
        List<User> users = userMapper.selectList(null);
        System.out.println(users);
        return users;
    }

    @PostMapping("/insert")
    public String insertUser(User user){
        int i = userMapper.insert(user);
        if(i>0){
            return "添加成功";
        }
        else {
            return "添加失败";
        }
    }

    @GetMapping("/user1")
    public User GetUser1(int id){
        User user1 = userMapper.selectById(id);
        return user1;
    }

    @GetMapping("/user/FindAll")
    public List<User> find(){
        return userMapper.selectAllUserAndAllOrder();
    }


    @GetMapping("/user/findByPage")
    public IPage findByPage(){
        Page<User> page = new Page<>(0,2);
        IPage iPage = userMapper.selectPage(page,null);
        return iPage;
    }


}
